package com.my.study.juc.basic;

/**
 * @author Carlos
 * @version 1.0
 * @Description 测试礼让，但不一定成功，只是让当前线程从运行状态变为就绪状态
 * @date 2021/4/7 23:01
 **/
public class TestYield {

    public static void main(String[] args) {
        MyYield myYield = new MyYield();

        new Thread(myYield, "A").start();
        new Thread(myYield, "B").start();
    }


}

class MyYield implements Runnable {

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "开始");
        // 礼让
        Thread.yield();
        System.out.println(Thread.currentThread().getName() + "结束");
    }
}
